package com.hup.minicontroller.server.model;

import com.hup.minicontroller.common.bluetooth.framework.BtChannel;
import com.hup.minicontroller.common.constant.NetConstant.ConnectType;
import com.hup.minicontroller.common.model.dto.LoginRequest;

import java.text.SimpleDateFormat;

import io.netty.channel.Channel;
import lombok.Data;

/**
 * 已连接的客户端
 */
@Data
public class OnlineClientSession {

    private ConnectType connectType;
    private String id;
    /**
     * 上线时间
     */
    private String loginTimeStr;

    //lan字段
    private String ip;
    private Channel channel;
    //蓝牙字段
    private BtChannel btChannel;

    public static OnlineClientSession lan(LoginRequest loginRequest, Channel channel) {
        OnlineClientSession res = new OnlineClientSession();
        res.connectType = ConnectType.LAN;
        res.id = loginRequest.getName();
        res.loginTimeStr = SimpleDateFormat.getTimeInstance().format(System.currentTimeMillis());
        res.ip = channel.remoteAddress().toString();
        res.channel = channel;
        return res;
    }

    public static OnlineClientSession bluetooth(LoginRequest loginRequest, BtChannel channel) {
        OnlineClientSession res = new OnlineClientSession();
        res.connectType = ConnectType.BLUETOOTH;
        res.id = loginRequest.getName();
        res.loginTimeStr = SimpleDateFormat.getTimeInstance().format(System.currentTimeMillis());
        res.btChannel = channel;
        return res;
    }

}
